<template>
  <div class="trans-record-content">
    <van-empty description="暂无数据" v-if="showEmpty" />
    <!-- <van-pull-refresh v-model="refreshing"> -->
    <van-list
      v-model="loading"
      :finished="finished"
      :finished-text="showEmpty ? '' : '没有更多了'"
      @load="onLoad"
    >
      <div class="record-item" v-for="(item,index) in list" :key="index" @click="toDetail(item)">
        <div class="item-top">
          <span class="name">{{item.record_name}}</span>
          <span class="time">{{item.record_date}}</span>
        </div>
        <div class="item-content">
          <div class="content-info">
            <p style="color:#FF6D24">{{item.dou_num}}</p>
            <span>豆数量</span>
          </div>
          <div class="content-info">
            <p>{{item.dou_money}}</p>
            <span>转让金额</span>
          </div>
        </div>
        <div class="item-footer">
          <div class="footer-ava">
            <van-image
              round
              width="24px"
              height="24px"
              fit="cover"
              :src="item.store_logo ? item.store_logo : defaultIcon"
            />
          </div>
          <div class="footer-name">{{item.store_name}}</div>
          <div class="footer-tag">
            <span
              :class="dataOption.record_states.filter(e =>{return e.value == item.record_state})[0].className"
            >{{dataOption.record_states.filter(e =>{return e.value == item.record_state})[0].name }}</span>
          </div>
        </div>
      </div>
    </van-list>
    <!-- </van-pull-refresh> -->
  </div>
</template>

<script>
import { List, Cell, Image, Toast, Empty, PullRefresh } from "vant";
import { getMessageBox } from "@/assets/js/utils";
import { queryTransRecords } from "@/api/api";
export default {
  name: "transRecord",
  components: {
    vanList: List,
    vanCell: Cell,
    VanImage: Image,
    vanEmpty: Empty,
    vanPullRefresh: PullRefresh,
  },
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      refreshing: false,
      pageNumber: 1,
      pageSize: 10,
      showEmpty: false,
      defaultIcon: require("../../../assets/images/default_user.png"),
      dataOption: {
        record_states: [
          {
            name: "转让中",
            value: 1,
            className: "type1",
          },
          {
            name: "转让成功",
            value: 2,
            className: "type2",
          },
          {
            name: "转让失败",
            value: 3,
            className: "type3",
          },
        ],
      },
    };
  },
  methods: {
    onLoad() {
      queryTransRecords({
        pageNumber: this.pageNumber,
        pageSize: this.pageSize,
      })
        .then((res) => {
          this.loading = false;
          if (res.code == 200000) {
            if (res.data.pageData instanceof Array) {
              this.list = this.list.concat(res.data.pageData);
              this.pageNumber += 1;
            }
            this.finished =
              res.data.pageData instanceof Array &&
              res.data.pageData.length >= this.pageSize
                ? false
                : true;
            this.showEmpty =
              Number.parseInt(res.data.totalItems) < 1 ? true : false;
          } else if (res.code == 300016) {
            this.showEmpty = true;
            this.list = [];
            this.finished = true;
          } else {
            this.finished = true;
          }
        })
        .catch((err) => {
          this.loading = false;
          this.finished = true;
        });
    },
    onRefresh() {
      // 清空列表数据
      this.finished = false;

      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true;
      this.onLoad();
    },
    // 详情
    toDetail(item) {
      this.$router.push({
        path: "/transRecordDetail",
        query: {
          record_id: item.record_id,
        },
      });
    },
  },
};
</script>

<style lang="less" scoped>
.trans-record-content {
  .record-item {
    width: 355px;
    height: 170px;
    background: rgba(255, 255, 255, 1);
    box-shadow: 0px 2px 24px 0px rgba(0, 0, 0, 0.04);
    border-radius: 10px;
    margin: 0 auto 10px;
    overflow: hidden;

    .item-top {
      height: 20px;
      line-height: 20px;
      // margin-top: 15px;
      margin: 15px;
      span.name {
        height: 20px;
        font-size: 14px;
        font-weight: 500;
        color: rgba(51, 51, 51, 1);
      }
      span.time {
        float: right;
        font-size: 12px;
        font-weight: 400;
        color: rgba(102, 102, 102, 1);
      }
    }
    .item-content {
      height: 69px;
      border-bottom: 1px solid #ececec;
      padding-left: 15px;
      .content-info {
        // margin-left: 15px;
        display: inline-block;
        vertical-align: middle;
        width: auto;
        min-width: 100px;
        margin-right: 50px;

        p {
          margin-top: 10px;
          height: 22px;
          font-size: 18px;
          font-family: DingMedium;
          color: #333333;
          font-weight: bold;
          line-height: 22px;
        }
        span {
          margin-top: 5px;
          height: 16px;
          font-size: 12px;
          color: rgba(153, 153, 153, 1);
          line-height: 16px;
          display: block;
        }
      }
    }
    .item-footer {
      height: 48px;
      position: relative;
      .footer-ava {
        margin-left: 15px;
        width: 24px;
        height: 24px;
        display: inline-block;
        vertical-align: middle;
      }
      .footer-name {
        text-align: left;
        white-space: nowrap;
        text-overflow: ellipsis;
        font-size: 12px;
        font-weight: 400;
        color: rgba(51, 51, 51, 1);
        line-height: 48px;
        display: inline-block;
        vertical-align: middle;
        max-width: 200px;
        margin-left: 10px;
        overflow: hidden;
      }
      .footer-tag {
        position: absolute;
        right: 0;
        top: 0;
        height: 100%;
        line-height: 48px;
        span {
          padding: 1px 5px 0;
          color: #fff;
          line-height: 20px;
          height: 20px;
          min-width: 42px;
          text-align: center;
          border-radius: 4px;
          display: inline-block;
          vertical-align: middle;
          margin-right: 14px;
        }
        span.type1 {
          background: #4197f5;
        }
        span.type2 {
          background: #5eb349;
        }
        span.type3 {
          background: #f85549;
        }
      }
    }
  }
}
</style>
